<!DOCTYPE html>
<html lang="zh">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>页面</title>
    <script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/loading.js"></script>
    <link href="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/theme-chalk/index.css" rel="stylesheet">

</head>
<body>
<div id="app">
    <el-container v-loading="loading" element-loading-text="正在为您准备数据,请稍后...">
        <el-header>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">合作商管理</el-breadcrumb-item>
                <el-breadcrumb-item>合同变更列表</el-breadcrumb-item>
            </el-breadcrumb>
        </el-header>
        <el-header>
            <el-row>
                <el-col :xs="14" :sm="14" :md="8" :lg="8" :xl="8">
                    <el-input placeholder="请输入内容" @keyup.enter.native="enterSearch" v-model="keySearch">
                        <el-button slot="append" icon="el-icon-search" @click=search></el-button>
                    </el-input>
                </el-col>
            </el-row>
        </el-header>
        <el-main>
            <el-table :data="tableData" stripe border style="width:100%" highlight-current-row size="mini"
                      tooltip-effect="dark" v-loading="tableLoading" height="calc(100vh - 240px)">
                <el-table-column label="序号" align="center" width="50px">
                    　　
                    <template scope="scope"><span>{{scope.$index+(currentPage - 1) * pageSize + 1}}</span>
                    </template>
                </el-table-column>
                　　
                <el-table-column prop="chgSmycode" label="合同增补编号" align="center"
                                 :show-overflow-tooltip=true></el-table-column>
                　　
                <el-table-column prop="chgSmyName" label="合同增补名称" align="center"
                                 :show-overflow-tooltip=true>

                </el-table-column>
                　　
                <el-table-column prop="stat" label="状态" align="center" :formatter="formatStatus"
                                 :show-overflow-tooltip=true></el-table-column>
                　　
                <el-table-column label="操作" align="center" min-width="100" fixed="right">
                    　　　　
                    <template slot-scope="scope">
                        <el-button type="text" @click="detail(scope.row)">查看</el-button>
                        <#if confirm!false>
                        <el-button type="text" v-if="scope.row.stat!='00'" @click="confirm(scope.row)">确认
                        </el-button>
                        </#if>　　　　
                        <#if refuse!false>
                        <el-button type="text" v-if="scope.row.stat=='02'" @click="refuse(scope.row)">拒绝
                        </el-button>
                        </#if>　
                    </template>
                    　　
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer>
            <el-row>
                <el-col>
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :page-sizes="[100, 500, 1000]" :page-size="pageSize"
                                   layout="total, sizes, prev, pager, next, jumper"
                                   :total="totalRecords">
                    </el-pagination>
                </el-col>
            </el-row>
        </el-footer>
    </el-container>
</div>

<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/dist/vue.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/index.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/publiccss/assets/global/plugins/jquery.min.js"
        type="text/javascript"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                loading: false,
                name: "",
                tableLoading: false,
                tableData: [],
                currentPage: 1, //当前页
                pageSize: 100, //每页总数
                totalRecords: 0, //总条数
                keySearch: '',
            };
            show:false

        },
        methods: {
            confirm(row) {
                this.$confirm('是否确认?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.submit(row.id, "00");
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            refuse(row) {
                this.$confirm('确认拒绝?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.submit(row.id, "01");
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            detail(row) {
                window.location.href = "/contractModifyController/detail.page?id=" + row.id;
            },
            submit(id, stat) {
                this.tableLoading = true;
                $.ajax({
                    url: '/contractModifyController/confirm.json',
                    type: 'post',
                    data: {id: id, stat: stat},
                    dataType: 'json',
                    success: (result) => {
                        this.tableLoading = false;
                        if (result.ret) {
                            this.$message({
                                type: 'success',
                                message: '操作成功'
                            });
                        } else {
                            this.$message.error('操作失败，请稍后重试');
                        }
                        this.ajaxFunction();
                    }
                });
            },
            //状态转换
            formatStatus: function (row, column) {
                return row.stat == "00" ? '已确认' : row.stat == "02" ? '未确认' : row.stat == "01" ? '已拒绝' : '未知';
            },
            //回车监听事件获取输入内容
            enterSearch(event) {
                this.currentPage = 1;
                this.pageSize = 100;
                this.keySearch = event.target.value;
                this.ajaxFunction();
            },
            //点击事件获取输入内容
            search() {
                this.currentPage = 1;
                this.pageSize = 100;
                this.ajaxFunction();
            },
            ajaxFunction() {
                this.tableLoading = true;
                $.ajax({
                    url: '/contractModifyController/contractChgSmyList.json',
                    type: 'get',
                    data: {key: this.keySearch, page: this.currentPage, limit: this.pageSize},
                    dataType: 'json',
                    success: (result) => {
                        this.tableLoading = false;
                        if (result.ret) {
                            this.tableData = result.data;
                            this.totalRecords = result.count;
                        }
                    }
                });
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.ajaxFunction();
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.ajaxFunction();
            },
        },

        mounted() {
            this.ajaxFunction();
        }
    })
</script>
</body>

</html>